package com.bridgeintelligent.tag.webserver.schedule.service.task;

import com.bridgeintelligent.tag.webserver.schedule.api.IStopService;
import com.bridgeintelligent.tag.webserver.schedule.api.ITaskLogService;
import com.bridgeintelligent.tag.webserver.schedule.api.enums.TaskEnum;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @description
 * @author: grp 2021-01-13 09:58
 **/
@Component
@Slf4j
@AllArgsConstructor
public class TagStopTask {
    private ITaskLogService taskLogService;
    private IStopService stopService;
    /**
     * 每天凌晨
     */
    @Scheduled(cron = "0 1 0 * * ?")
    public void stopJob() {
        log.info("停用任务 开始");
        String date = DateFormatUtils.format(new Date(),"yyyy-MM-dd");
        // 组合标签 定制 过期 自动停用
        stopService.stopTags(date);
        // 组合标签-客群失效
        stopService.stopCustomers();
        log.info("停用任务 结束");
        taskLogService.save(TaskEnum.TASK_TAG_STOP.getId());
    }
}
